package com.sojson.util.sms;

import java.util.Date;
import java.util.Map;

import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.sojson.util.sms.impl.SmsUtilImpl;

/**
 * 短信工具类接口
 * 
 * @author liu
 * @Date 2020-06-28 15:40:39
 * @Description
 *
 */
public class SmsUtil {

    private static final SmsUtilInterface smsUtilsInterface = SmsUtilImpl.getInstances();

    /**
     * 发送短信接口
     * 
     * @param templateNameCode 阿里云短信模板代码
     * @param tel 发送到哪个手机号
     * @return
     * @throws Exception
     */
    public static SendSmsResponse sendSms(String templateNameCode, String tel) throws Exception {
        return smsUtilsInterface.sendSms(templateNameCode, null, tel);
    }

    /**
     * 发送短信接口
     * 
     * @param templateNameCode 阿里云短信模板代码
     * @param param 验证码，从SmsTemplate类获取
     * @param tel 发送到哪个手机号
     * @return
     * @throws Exception
     */
    public static SendSmsResponse sendSms(String templateNameCode, Map<String, String> param, String tel)
        throws Exception {
        return smsUtilsInterface.sendSms(templateNameCode, param, tel);
    }

    /**
     * 查明细接口
     * 
     * @param tel
     * @param bizId 此ID从状态信息类SendSmsResponse获取
     * @param pageSum
     * @param pageSize
     * @param date
     * @return
     * @throws Exception
     */
    public static QuerySendDetailsResponse querySendDetails(String tel, String bizId, Long pageSum, Long pageSize,
        Date date) throws Exception {
        return smsUtilsInterface.querySendDetails(tel, bizId, pageSum, pageSize, date);
    }

    // public static void main(String[] args) throws ClientException, InterruptedException {
    //
    // // 发短信
    // SendSmsResponse response = sendSms("15896821518", "123456");
    // System.out.println("短信接口返回的数据----------------");
    // System.out.println("Code=" + response.getCode());
    // System.out.println("Message=" + response.getMessage());
    // System.out.println("RequestId=" + response.getRequestId());
    // System.out.println("BizId=" + response.getBizId());
    //
    // Thread.sleep(3000L);
    //
    // // 查明细
    // if (StringUtils.isNotBlank(response.getCode()) && StringUtils.equals("OK", response.getCode())) {
    // QuerySendDetailsResponse querySendDetailsResponse = querySendDetails(response.getBizId());
    // System.out.println("短信明细查询接口返回数据----------------");
    // System.out.println("Code=" + querySendDetailsResponse.getCode());
    // System.out.println("Message=" + querySendDetailsResponse.getMessage());
    // int i = 0;
    // for (QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO : querySendDetailsResponse
    // .getSmsSendDetailDTOs()) {
    // System.out.println("SmsSendDetailDTO[" + i + "]:");
    // System.out.println("Content=" + smsSendDetailDTO.getContent());
    // System.out.println("ErrCode=" + smsSendDetailDTO.getErrCode());
    // System.out.println("OutId=" + smsSendDetailDTO.getOutId());
    // System.out.println("PhoneNum=" + smsSendDetailDTO.getPhoneNum());
    // System.out.println("ReceiveDate=" + smsSendDetailDTO.getReceiveDate());
    // System.out.println("SendDate=" + smsSendDetailDTO.getSendDate());
    // System.out.println("SendStatus=" + smsSendDetailDTO.getSendStatus());
    // System.out.println("Template=" + smsSendDetailDTO.getTemplateCode());
    // }
    // System.out.println("TotalCount=" + querySendDetailsResponse.getTotalCount());
    // System.out.println("RequestId=" + querySendDetailsResponse.getRequestId());
    // }
    //
    // }

}